package com.app.micaihu.custom.view.dataview;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.core.widget.NestedScrollView;

import com.android.volley.VolleyError;
import com.app.micaihu.R;
import com.app.micaihu.ad.AdConfig;
import com.app.micaihu.adapter.NewsAboutAdapter;
import com.app.micaihu.base.bean.DataBean;
import com.app.micaihu.bean.ad.NativeAd;
import com.app.micaihu.bean.infor.AttentionStautsBean;
import com.app.micaihu.bean.news.NewsContent;
import com.app.micaihu.bean.news.NewsEntity;
import com.app.micaihu.bean.speak.ILaud;
import com.app.micaihu.configure.ActivityRequestCode;
import com.app.micaihu.configure.Config;
import com.app.micaihu.configure.TypeConstant;
import com.app.micaihu.configure.URIContant;
import com.app.micaihu.configure.UmEventId;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.micaihu.listener.HttpListener;
import com.app.micaihu.listener.LaudListener;
import com.app.micaihu.manager.UserInforManager;
import com.app.micaihu.utils.HttpUtils;
import com.app.micaihu.utils.ImageLoadUtils;
import com.app.micaihu.utils.InteractiveUtils;
import com.app.micaihu.utils.MobclickAgentUtils;
import com.app.micaihu.view.army.activity.ArmyDetailActivity;
import com.app.micaihu.view.army.activity.ArmyMedalListActivity;
import com.app.micaihu.view.newsdetail.NewsDetailActivity;
import com.app.micaihu.view.newsdetail.view.NewsDetailWebView;
import com.app.micaihu.view.user.userinfo.activity.MyHomepageDynamicActivity;
import com.app.utils.util.ToastUtils;
import com.app.utils.util.ViewSizeUtils;
import com.app.utils.util.image.LoadImageUtils;
import com.baidu.mobstat.StatService;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ViewUtils;
import com.google.gson.reflect.TypeToken;

import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

/**
 * 内容详情自定义View
 * Created by linkai on 2016/11/3.
 */
public class DetailNewsView extends NestedScrollView implements View.OnClickListener {

    private TextView newsTitle;//文章标题
    private TextView userName;//用户名字
    private TextView userRank;//用户军衔名称
    private TextView tvArmyGroupInfo;//用户军衔名称
    private CustomImageView userRankIcon;//用户军衔图标
    private ImageView ivHonourPic;//用户军衔图标
    private TextView newsTime;//新闻时间
    private CustomImageView userHead;//用户头像
    private LinearLayout attentionBtn;//用户关注
    private View attentionPro;//关注加载按钮
    private ImageView attentionImg;//关注图片
    private TextView attentionText;//关注文字
    private FrameLayout laudContainer;
    private FrameLayout dislikeContainer;
    public TextView praiseView;//点赞
    public TextView stepView;//点踩
    public NewsDetailWebView webview;//显示内容的容器
    private ListView aboutNewsListView;//相关新闻
    private LinearLayout bootomLayout;//下方布局layout

    private ScrollCallback scrollCallback;//操作监听
    public FrameLayout rlBottomAd;//

    private NewsContent mNewsContent;//
    private Context context;
    public String httpName;//数据请求的标识
    private float webviewY;//webview的坐标
    private FrameLayout webViewContainer;
    public View expends;
    private NewsDetailActivity detailActivity;
    public View expendsTop;
    public boolean isExpend;


    public DetailNewsView(Context context) {
        super(context);
        this.context = context;
    }

    public DetailNewsView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }


    /**
     * 初始化控件
     */
    public void init(NewsDetailActivity detailActivity) {
        this.detailActivity = detailActivity;
        inflate(getContext(), R.layout.view_detailnews, this);
        webViewContainer = (FrameLayout) findViewById(R.id.webView_container);
        rlBottomAd = (FrameLayout) findViewById(R.id.rlBottomAd);

        webview = new NewsDetailWebView(context);
        webViewContainer.addView(webview, 0);

        newsTitle = (TextView) findViewById(R.id.tv_newstitle);
        userName = (TextView) findViewById(R.id.tv_author_titile);
        userRank = (TextView) findViewById(R.id.tv_author_rank_name);
        userRankIcon = (CustomImageView) findViewById(R.id.cv_author_rank);
        ivHonourPic = findViewById(R.id.ivHonourPic);
        tvArmyGroupInfo = findViewById(R.id.tvArmyGroupInfo);
        newsTime = (TextView) findViewById(R.id.tv_news_time);
        userHead = (CustomImageView) findViewById(R.id.cv_author_head);
        attentionBtn = (LinearLayout) findViewById(R.id.attention_btn);
        attentionPro = findViewById(R.id.attention_load);
        attentionImg = (ImageView) findViewById(R.id.attention_img);
        attentionText = (TextView) findViewById(R.id.attention_text);
//        webview = (NewsDetailWebView) findViewById(R.id.cwv_webview);
        praiseView = (TextView) findViewById(R.id.tv_detail_zan);
        stepView = (TextView) findViewById(R.id.tv_detail_cai);
        bootomLayout = (LinearLayout) findViewById(R.id.detail_bottom_layout);
        laudContainer = (FrameLayout) findViewById(R.id.fl_laud_container);
        dislikeContainer = (FrameLayout) findViewById(R.id.fl_dislike_container);


        //展开全文
        expends = findViewById(R.id.click_expend);
        expendsTop = findViewById(R.id.click_expend_top);
        expends.setVisibility(View.GONE);
        expendsTop.setVisibility(View.GONE);

        expends.setOnClickListener(this);
        userHead.setOnClickListener(this);
        userName.setOnClickListener(this);
        userRank.setOnClickListener(this);
        userRankIcon.setOnClickListener(this);
        attentionBtn.setOnClickListener(this);
        laudContainer.setOnClickListener(this);
        dislikeContainer.setOnClickListener(this);

        ivHonourPic.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mNewsContent != null && !StringUtils.isEmpty(mNewsContent.getAuthorId())) {
                    Intent intent = new Intent(context, ArmyMedalListActivity.class);
                    intent.putExtra(Config.Extra.toUid, mNewsContent.getAuthorId());
                    ActivityUtils.startActivity(intent);
                }
            }
        });
        tvArmyGroupInfo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mNewsContent != null && !StringUtils.isEmpty(mNewsContent.getAuthorId()) && !StringUtils.isEmpty(mNewsContent.getGid())) {
                    Intent intent = new Intent(context, ArmyDetailActivity.class);
                    intent.putExtra(Config.Extra.toUid, mNewsContent.getAuthorId());
                    intent.putExtra(Config.Extra.id, mNewsContent.getGid());
                    ActivityUtils.startActivity(intent);
                }
            }
        });

    }

    public void setScrollCallback(ScrollCallback scrollCallback) {
        this.scrollCallback = scrollCallback;
    }


    /**
     * 滑动接口
     */
    public interface ScrollCallback {
        public void scroll(int l, int t, int oldl, int oldt);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (scrollCallback != null) {
            scrollCallback.scroll(l, t, oldl, oldt);
        }

    }


    /**
     * 加载新闻内容
     *
     * @param newscontent
     */
    public void setNewsData(NewsContent newscontent) {

        this.mNewsContent = newscontent;

        //加载数据
        if (TextUtils.equals(mNewsContent.getArticleType(), TypeConstant.NEWS_WEB)) {
            webview.loadUrl(mNewsContent.getArticleUrl());
        } else {
            //替换图片
            String content = webview.replaceImg(mNewsContent.getArticleContent());
            webview.loadDataWithBaseURL(null, content, "text/html", "utf-8", "");
        }
        if (TextUtils.equals(mNewsContent.getArticleType(), TypeConstant.NEWS_NORMAL)
                || TextUtils.equals(mNewsContent.getArticleType(), TypeConstant.NEWS_MARKET)
                || TextUtils.equals(mNewsContent.getArticleType(), TypeConstant.EXCLUSIVE_NEWS_BIG_IMAGE)) {
            LoadImageUtils.getInstance().loadCircleImage(this.userHead, mNewsContent.getAuthorHeadPic());
            LoadImageUtils.getInstance().loadImage(this.userRankIcon, mNewsContent.getAuthorRankIcon());
            ImageLoadUtils.loadImage(mNewsContent.getHonourPic(), ivHonourPic);
            this.tvArmyGroupInfo.setText(mNewsContent.getArmyGroupInfo());
            this.newsTitle.setText(mNewsContent.getArticleTitle());
            this.userName.setText(mNewsContent.getAuthorName());
            this.userRank.setText(mNewsContent.getAuthorRankName());
            this.newsTime.setText(mNewsContent.getArticleTime());
            this.praiseView.setText(getContext().getString(R.string.common_zan_newsup, mNewsContent.getArticleLaud()));
            this.stepView.setText(getContext().getString(R.string.common_zan_newsdown, mNewsContent.getDislikeNum()));
            changeAttentionState(mNewsContent.getStatus());
        } else {
            findViewById(R.id.rl_newstitle_layout).setVisibility(View.GONE);
            this.newsTitle.setVisibility(View.GONE);
        }
    }

    /**
     * 分享是否隐藏
     *
     * @param marketAd 是否是电商
     */
    public void setMarketAd(boolean marketAd) {
        if (marketAd) {
            findViewById(R.id.ll_share).setVisibility(View.GONE);
        } else {
            findViewById(R.id.ll_share).setVisibility(View.VISIBLE);
        }
    }

    /**
     * 继续播放视频
     */
    public void resumeWebview() {
        if (webview != null) {
            //继续播放视频
            webview.play();
        }

    }

    /**
     * 停止webview
     */
    public void stopWebview() {
        if (this.webview != null) {
            this.webview.stop();
        }
    }

    /**
     * 销毁webview
     */
    public void destoryWebview() {
        if (webview != null) {
            webview.destroy();
            webview = null;
        }


        if (aboutNewsListView != null) {
            aboutNewsListView = null;
        }

    }

    public void showAboutNews() {
        if (mNewsContent != null && (TextUtils.equals(mNewsContent.getArticleType(), TypeConstant.NEWS_NORMAL)
                || TextUtils.equals(mNewsContent.getArticleType(), TypeConstant.NEWS_MARKET)
                || TextUtils.equals(mNewsContent.getArticleType(), TypeConstant.EXCLUSIVE_NEWS_BIG_IMAGE))) {
            ViewUtils.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (bootomLayout != null && webview != null) {
                        bootomLayout.setVisibility(View.VISIBLE);
                    }
                }
            });
        } else if (mNewsContent != null && TextUtils.equals(mNewsContent.getArticleType(), TypeConstant.NEWS_WEB)) {
            ViewUtils.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (bootomLayout != null && webview != null) {
                        bootomLayout.setVisibility(View.GONE);
                    }
                }
            });
        }


    }

    /**
     * 设置相关新闻
     *
     * @param newsEntityList
     * @param adList
     */
    public void setAboutData(final List<NewsEntity> newsEntityList, final List<NativeAd> adList,
                             final List<NativeAd> addetailList, final OnClickListener shareClick) {
        if (newsEntityList != null && newsEntityList.size() > 0) {
            if (webview == null) {
                //说明此页面已经退出,所以不再执行才操作
                return;
            }
            //适配相关新闻部分
            aboutNewsListView = (ListView) findViewById(R.id.lv_aboutlist);
            View headview = LayoutInflater.from(context).inflate(R.layout.layout_driver_title, null);
            headview.setPadding(ViewSizeUtils.dp2px(context, 14), 0, ViewSizeUtils.dp2px(context, 14), 0);
            headview.setEnabled(false);
            headview.setClickable(false);
            headview.setBackgroundColor(getResources().getColor(R.color.news_detail_page_bg));
            aboutNewsListView.addHeaderView(headview);
            for (int i = 0; i < newsEntityList.size(); i++) {
                //删除没有匹配上的文章类型
                if (TextUtils.isEmpty(TypeConstant.getNewsTypeName(newsEntityList.get(i).getArticleType()))) {
                    newsEntityList.remove(i);
                    i--;
                    continue;
                }
            }
            //干扰数据添加广告
            AdConfig.insertAd(newsEntityList, addetailList, 0, 0, null);
//            NewsEntity newsEntity = new NewsEntity();
//            newsEntity.setArticleTitle("11111");
//            newsEntityList.add(newsEntity);
//            newsEntityList.add(newsEntity);
//            newsEntityList.add(newsEntity);
            NewsAboutAdapter aboutAdapter = new NewsAboutAdapter(newsEntityList, context);
            aboutNewsListView.setAdapter(aboutAdapter);

            int height = SizeUtils.dp2px(mNewsContent.getAboultNewsHeight());

            LogUtils.e("sizeUtils", "height->" + height);
            //通过父控件进行高度的申请
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.topMargin = SizeUtils.dp2px(20);
            params.height = height;
            aboutNewsListView.setLayoutParams(params);

//            getListViewSelfHeight();

            aboutNewsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    if (position == 0 || newsEntityList == null) {
                        return;
                    }
                    position = position - 1;
                    //防止越界
                    if (position >= newsEntityList.size()) {
                        position = newsEntityList.size() - 1;
                    } else if (position < 0) {
                        position = 0;
                    }
                    NewsEntity newsEntity = newsEntityList.get(position);
                    if (TypeConstant.NEWS_NORMAL.equals(newsEntity.getArticleType())) {
                        MobclickAgentUtils.event(UmEventId.articleabout_click, "相关文章");
                    } else if (TypeConstant.VIDEO_NORMAL.equals(newsEntity.getArticleType())) {
                        MobclickAgentUtils.event(UmEventId.videoabout_click, "相关文章");
                    }
                    TypeConstant.openTypeDetail(newsEntity, (Activity) context, TypeConstant.SOURCETYPE_ABOUT);
                }
            });
            //添加分享上边的广告牌
            insertAd(adList);
            //设置分享点击以及点赞记录
            setShareOnclick(shareClick);

            return;
        }
        if (webview == null) {
            //说明此页面已经退出,所以不再执行才操作
            return;
        }
        //添加分享上边的广告牌
        insertAd(addetailList);
        //设置分享点击以及点赞记录
        setShareOnclick(shareClick);
    }

    public void getListViewSelfHeight() {
        if (aboutNewsListView == null) return;
        // 获取ListView对应的Adapter
        ListAdapter listAdapter = aboutNewsListView.getAdapter();
        //健壮性的判断
        if (listAdapter == null) {
            return;
        }
        // 统计所有子项的总高度
        int totalHeight = 0;
        for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
            // listAdapter.getCount()返回数据项的数目
            View listItem = listAdapter.getView(i, null, aboutNewsListView);
            // 调用measure方法 传0是测量默认的大小
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }
        //通过父控件进行高度的申请
        ViewGroup.LayoutParams params = aboutNewsListView.getLayoutParams();
        //listAdapter.getCount() - 1 从零开始 listView.getDividerHeight()获取子项间分隔符占用的高度
        params.height = totalHeight + (aboutNewsListView.getDividerHeight() * (listAdapter.getCount() - 1));
        aboutNewsListView.setLayoutParams(params);
    }

    /**
     * 初始化分享以及本地点赞记录
     */
    public void setShareOnclick(OnClickListener onClickListener) {
        if (mNewsContent != null) {
            //查询本地的赞
            if (InteractiveUtils.getInstance().theLaudIsContains(mNewsContent.getArticleId(), true)) {
                praiseView.setEnabled(false);
                laudContainer.setTag(true);
            } else {
                praiseView.setEnabled(true);
                laudContainer.setTag(mNewsContent);
            }

            if (InteractiveUtils.getInstance().theLaudIsContains(mNewsContent.getArticleId(), false)) {
                stepView.setEnabled(false);
                dislikeContainer.setTag(true);
            } else {
                stepView.setEnabled(true);
                dislikeContainer.setTag(mNewsContent);
            }

        }

        findViewById(R.id.iv_appright2).setOnClickListener(onClickListener);
        Button shareBtn = (Button) findViewById(R.id.detail_stylewechat);
        shareBtn.setOnClickListener(onClickListener);
        changeShareView(shareBtn.getCompoundDrawables()[1]);
        shareBtn = (Button) findViewById(R.id.detail_wechatmoments);
        shareBtn.setOnClickListener(onClickListener);
        changeShareView(shareBtn.getCompoundDrawables()[1]);
        shareBtn = (Button) findViewById(R.id.detail_weibo);
        shareBtn.setOnClickListener(onClickListener);
        changeShareView(shareBtn.getCompoundDrawables()[1]);
        shareBtn = (Button) findViewById(R.id.detail_qq);
        shareBtn.setOnClickListener(onClickListener);
        changeShareView(shareBtn.getCompoundDrawables()[1]);
    }

    /**
     * 改变分享图片的大小
     *
     * @param drawable
     */
    private void changeShareView(Drawable drawable) {
        if (drawable == null) {
            return;
        }
        drawable.setBounds(ViewSizeUtils.dp2px(context, 5), ViewSizeUtils.dp2px(context, 5),
                ViewSizeUtils.dp2px(context, 55), ViewSizeUtils.dp2px(context, 55));
    }


    /**
     * 添加广告
     *
     * @param adList
     */
    private void insertAd(List<NativeAd> adList) {
        if (mNewsContent != null && !TextUtils.isEmpty(mNewsContent.getEmokoCmt())) {
            //添加虎哥点评
            findViewById(R.id.iv_emokocmt_img).setVisibility(View.VISIBLE);
            TextView comt = (TextView) findViewById(R.id.tv_emokocmt_text);
            comt.setText(mNewsContent.getEmokoCmt());
            comt.setVisibility(View.VISIBLE);
        }
        if (adList == null || adList.size() == 0) {
            return;
        }
        NativeAd nativeAd = adList.get(0);
        if (nativeAd == null) {
            return;
        }
//        View adView = AdConfig.getAboutNativeAdView(context, nativeAd, 0, null, null);
        View adView = AdConfig.getArticleBottomNativeAdView(context, nativeAd, 0, null, UmEventId.INSTANCE.getArticlebottom());
        if (adView != null) {
            if (bootomLayout != null) {
                bootomLayout.addView(adView, 0);
            }
//            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
//                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//            layoutParams.setMargins(ViewSizeUtils.dp2px(context, 15), 0, ViewSizeUtils.dp2px(context, 15), 0);
//            adView.setLayoutParams(layoutParams);

        }
    }


    /**
     * 内容滑动到最底端
     *
     * @return
     */
    public void scrollBottom() {
        fullScroll(ScrollView.FOCUS_DOWN);//滚动到底部
    }

    @Override
    public void onClick(View v) {
        if (v == null || mNewsContent == null || context == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.cv_author_head:
            case R.id.tv_author_titile:
            case R.id.tv_author_rank_name:
            case R.id.cv_author_rank:
                MyHomepageDynamicActivity.goToUserHomePage(ActivityUtils.getTopActivity(), mNewsContent.getAuthorId(), ActivityRequestCode.REQUEST_CODE_USERHOME);
                break;
            case R.id.attention_btn://关注
                MobclickAgentUtils.event(UmEventId.attentionbutton_click, "文章顶部");
                if (v.getTag() == null || mNewsContent == null) {
                    return;
                }
                //关注
                attention(mNewsContent.getAuthorId() + "", v.getTag().toString());
                StatService.onEvent(this.context, "033", "新闻关注作者", 1);// 统计的点击
                break;
//            case R.id.tv_detail_zan://赞
            case R.id.fl_laud_container://赞
//                zan("0");
                laudOpration(true, v);
                StatService.onEvent(context, "036", "新闻点赞", 1);// 统计的点击
                break;
//            case R.id.tv_detail_cai://踩
            case R.id.fl_dislike_container:
//                zan("2");
                laudOpration(false, v);
                StatService.onEvent(context, "036", "新闻点踩", 1);// 统计的点击
                break;
            case R.id.click_expend://查看全文
                if (expends != null && expends.getVisibility() == View.VISIBLE) {
                    if (webview != null && webview.getLayoutParams() != null) {
                        isExpend = true;
                        expends.setVisibility(View.GONE);
                        expendsTop.setVisibility(View.GONE);
                        ViewGroup.LayoutParams layoutParams = webview.getLayoutParams();
//                        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
                        layoutParams.height = SizeUtils.dp2px(webview.getContentHeight());
                        webview.setLayoutParams(layoutParams);
                        webview.requestLayout();

                    }
                }

                break;
        }
    }


    /**
     * 关注操作
     *
     * @param toUid
     * @param state
     */
    public void attention(String toUid, String state) {
        if (TextUtils.isEmpty(toUid)) {
            return;
        }
        if (!UserInforManager.getInstance().isLogin()) {
            UserInforManager.getInstance().toLoginPage((Activity) context);
            return;
        }
        Map<String, String> params = new HashMap<>();
        params.put("uid", UserInforManager.getInstance().getUserInfor().getUid());
        params.put("toUid", toUid);
        String currentRequestType;
        if (TextUtils.equals(state, "0")) {     //未关注->点击去关注
            currentRequestType = "1";
        } else {
            //取消关注
            currentRequestType = "2";
        }
        params.put("type", currentRequestType);

        HttpListener<DataBean<AttentionStautsBean>> attentionListener = new HttpListener<DataBean<AttentionStautsBean>>() {
            @Override
            public void onStart() {
                if (attentionImg != null) {
                    attentionImg.setVisibility(View.GONE);
                }
                if (attentionPro != null) {
                    attentionPro.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onError(VolleyError error) {
                if (attentionPro != null) {
                    attentionPro.setVisibility(View.GONE);
                }
                if (attentionImg != null) {
                    attentionImg.setVisibility(View.VISIBLE);
                }
                ToastUtils.makeText(getResources().getString(R.string.neterror_click));
            }

            @Override
            public void onSuccess(DataBean<AttentionStautsBean> response) {
                if (attentionPro != null) {
                    attentionPro.setVisibility(View.GONE);
                }
                if (attentionImg != null) {
                    attentionImg.setVisibility(View.VISIBLE);
                }
                if (response.noError() && response.getData() != null) {
                    AttentionStautsBean attentionStautsBean = response.getData();
                    changeAttentionState(attentionStautsBean.getStatus());
                } else {
                    ToastUtils.makeText("关注失败");
                }
            }
        };

        HttpUtils.addPostRequest(URIContant.ATTENTION_OR_NO, new TypeToken<DataBean<AttentionStautsBean>>() {
        }.getType(), httpName, params, attentionListener);
    }

    /**
     * 改变关注状态
     *
     * @param state
     */
    public void changeAttentionState(String state) {
        this.attentionBtn.setTag(state);
        if (TextUtils.equals(state, TypeConstant.ATTENTION_NO)) {
            this.attentionBtn.setSelected(true);
            this.attentionText.setText("关注");
            this.attentionText.setSelected(false);
            this.attentionImg.getBackground().setLevel(3);
        } else if (TextUtils.equals(state, TypeConstant.ATTENTION_YES)) {
            this.attentionBtn.setSelected(false);
            this.attentionText.setText("已关注");
            this.attentionText.setSelected(true);
            this.attentionImg.getBackground().setLevel(5);
        } else if (TextUtils.equals(state, TypeConstant.ATTENTION_ALL)) {
            this.attentionBtn.setSelected(false);
            this.attentionText.setText("互相关注");
            this.attentionText.setSelected(true);
            this.attentionImg.getBackground().setLevel(1);
        }
    }

    /**
     * 点赞的动作
     *
     * @param like
     * @param v
     */
    private void laudOpration(boolean like, View v) {
        if (laudContainer == null || mNewsContent == null || dislikeContainer == null) {
            ToastUtils.makeText(R.drawable.handle_fail, "点赞失败");
            return;
        }
        if (laudContainer.getTag() == null || dislikeContainer.getTag() == null) {
            return;
        }
        if ((laudContainer.getTag() instanceof Boolean && Boolean.valueOf(laudContainer.getTag().toString()))
                || (dislikeContainer.getTag() instanceof Boolean && Boolean.valueOf(dislikeContainer.getTag().toString()))) {
            return;
        }

        mNewsContent.setLike(like);
        InteractiveUtils.getInstance().laud((FrameLayout) v, laudListener);
    }

    /**
     * 点赞的监听
     */
    private LaudListener laudListener = new LaudListener() {
        @Override
        public void startCommit(ILaud iLaud) {

        }

        @Override
        public void finish(ILaud iLaud) {
            if (stepView == null || praiseView == null) return;
            if (TextUtils.equals(iLaud.getILaudOperateType(), TypeConstant.ZAN_DISLIKE)) {
                stepView.setText(getResources().getString(R.string.common_zan_newsdown, iLaud.getILaudNum()));
                praiseView.setTag(true);
            } else {
                praiseView.setText(getResources().getString(R.string.common_zan_newsup, iLaud.getILaudNum()));
                stepView.setTag(true);
            }
        }
    };


    public float getWebviewY() {
        if (webviewY == 0 && webview != null) {
            webviewY = webview.getY();
        }
        return webviewY;
    }

}
